/**
*      author: Y_Yao
*      created: 2024-11-17 15:41:42
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 5e5 + 7;
int l[N],r[N],col[N],sz[N],ret[N];

int findl(int x)
{
    if(l[x] != x) l[x] = findl(l[x]);
    return l[x];
}

int findr(int x)
{
    if(r[x] != x) r[x] = findr(r[x]);
    return r[x];
}

void Union(int a,int b)
{
    int al = findl(a),bl = findl(b);
    int ar = findr(a),br = findr(b);
    if(al != bl)
    {
        l[bl] = al,r[ar] = br,sz[br] += sz[ar];
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n,q;
    cin >> n >> q;
    for(int i = 1;i <= n;i++)
    {
        l[i] = i,r[i] = i,col[i] = i,sz[i] = 1,ret[i] = 1;
    }
    while(q--)
    {
        int op;
        cin >> op;
        if(op == 1)
        {
            int x,c;
            cin >> x >> c;
            ret[col[findr(x)]] -= sz[findr(x)];
            ret[c] += sz[findr(x)];

            if(col[findr(findl(x) - 1)] == c) Union(findl(x) - 1,x);
            if(col[findr(findr(x) + 1)] == c) Union(x,findr(x) + 1);

            col[findr(x)] = c;
        }
        else {
            int c;
            cin >> c;
            cout << ret[c] << endl;
        }
    }
    return 0;
}